#ifndef __EXLOBBY_AVATAR_NODE__
#define __EXLOBBY_AVATAR_NODE__

#include "ExLobbyDDL.h"
#include <ServerBase.h>
#include "ExLobbyAvatarGameMgr.h"

namespace Atlas
{
	class CExLobbyAvatarComponent;
	class CExLobbyAvatarNodeServer;
	class CExLobbyAvatarNodeClient;

	class CExLobbyAvatarComponent : public CServerComponent
	{
	public:
		typedef DDLStub::LOBBY_C2S<CExLobbyAvatarNodeClient, CExLobbyAvatarComponent>						LOBBY_C2S_STUB;
		typedef CNodeStub<LOBBY_C2S_STUB, CExLobbyAvatarNodeClient, CExLobbyAvatarComponent>				LOBBY_STUB;

		CExLobbyAvatarComponent(CExLobbyAvatarNodeServer* pServer);
		virtual ~CExLobbyAvatarComponent();

		void Echo(CExLobbyAvatarNodeClient* pClient, const char* szEcho );
		void GetAvatar(CExLobbyAvatarNodeClient* pClient);
		void CreateAvatar(CExLobbyAvatarNodeClient* pClient, const char* name);
		void SelectAvatar(CExLobbyAvatarNodeClient* pClient, _U32 aid);

		void ListRoom(CExLobbyAvatarNodeClient* pClient, _U64 id);
		void CreateRoom(CExLobbyAvatarNodeClient* pClient, const char* name);
		void EnterRoom(CExLobbyAvatarNodeClient* pClient, _U64 id);
		void LeaveRoom(CExLobbyAvatarNodeClient* pClient);

		void SendMessage(CExLobbyAvatarNodeClient* pClient, const char* msg);

	private:
		LOBBY_STUB m_LobbyStub;
		GameMgr m_GameMgr;
	};

	class CExLobbyAvatarNodeServer : public CNodeServer
	{
	public:
		CExLobbyAvatarNodeServer(CServerApp* pServerApp);
		virtual ~CExLobbyAvatarNodeServer();

		virtual CNodeClient* NewNodeClient(_U64 nndx, _U64 cndx, HSERVER hCluster);
	};

	class CExLobbyAvatarNodeClient : public CNodeClient
	{
	public:
		CExLobbyAvatarNodeClient(CExLobbyAvatarNodeServer* pServer, _U64 nndx, _U64 cndx, HSERVER hCluster);
		virtual ~CExLobbyAvatarNodeClient();

		virtual void OnConnect(_U32 len, const _U8* data);
		virtual void OnDisconnect();
		virtual void OnData(_U16 code, _U32 len, const _U8* data);
		virtual void OnEvent(_U16 code, _U32 len, const _U8* data);

		DDLProxy::LOBBY_S2C<CExLobbyAvatarNodeClient, DDL::TMemoryWriter<1*1024>> Lobby;

		_U64 GetRoomID();
		void SetRoomID(_U64 RoomID);

		EXLOBBY_AVATAR& GetAvatar();
		void SetAvatar(EXLOBBY_AVATAR& Avatar);

		static _U32 NewAvatarID();

	private:
		_U64 m_RoomID;
		EXLOBBY_AVATAR m_Avatar;
		static _U32 ms_AvatarAlloc;
	};

}

#endif
